package com.example.understand_compose1.testcase_compose.page

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.understand_compose1.R


val LocalTextColor = compositionLocalOf { Color.Unspecified }
@Composable
fun PhotographerCard(modifier: Modifier = Modifier) {
    Row(
        // 修饰一下
        modifier = modifier.clip(RoundedCornerShape(4.dp))
            .background(color = MaterialTheme.colorScheme.surface)
            .clickable {
                // 点击debug输出
                Log.d("TAG","Row click")
            }.padding(16.dp)
    ) {
        Surface(modifier = Modifier.size(50.dp),
            shape = CircleShape,
            // 复制onSurface颜色，但是alpha要变一下
            color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f)
        ) {
            Image(
                painter = painterResource(id = R.drawable.ic_launcher_foreground),
                contentDescription = "默认安装icon",
            )
        }
        Column(
            // 修饰一下
            modifier = Modifier.padding(start = 8.dp)
                .align(Alignment.CenterVertically)
        ) {
            Text(
                text = "Alfred Sisley",
                fontWeight = FontWeight.Bold
            )
            // 透明度设置
            CompositionLocalProvider(LocalTextColor provides Color.Red) {
                Text(
                    text = "3 minutes ago",
                    style = MaterialTheme.typography.bodyMedium
                )
            }
        }
    }
}

@Preview
@Composable
fun PreviewPhotographerCard() {
    PhotographerCard()
}